﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Kaskelot.Services.Model;

namespace Stockholm.SOA.Kaskelot.WCF.ServiceImplementation.Mapping
{
	public static class GruppExtensions
	{
		public static DataContracts.Grupp ToContract(this Grupp entity)
		{
			DataContracts.Grupp b = new DataContracts.Grupp();

			CopyFromEntity(entity, b, false);

			return b;
		}

		public static DataContracts.Grupp ToMinimalContract(this Grupp entity)
		{
			DataContracts.Grupp b = new DataContracts.Grupp();

			CopyFromEntity(entity, b, true);

			return b;
		}

		public static Grupp ToEntity(this DataContracts.Grupp b)
		{
			Grupp entity = new Grupp();

			CopyToEntity(b, entity);

			return entity;
		}

		public static void UpdateEntity(this Grupp entity, DataContracts.Grupp Grupp)
		{
			CopyToEntity(Grupp, entity);
		}

		private static void CopyFromEntity(Grupp from, DataContracts.Grupp to, bool minimal)
		{
			to.Id = from.Id;
			to.ValId = from.ValId;

			to.Andrad = from.Andrad;
			to.AndradAv = from.AndradAv;
			to.Skapad = from.Skapad;
			to.SkapadAv = from.SkapadAv;

			to.Namn = from.Benamning;
			to.Fritext = from.Fritext;
		}

		private static void CopyToEntity(DataContracts.Grupp from, Grupp to)
		{
			to.Id = from.Id;
			to.ValId = from.ValId;

			to.Andrad = from.Andrad;
			to.AndradAv = from.AndradAv;
			to.Skapad = from.Skapad;
			to.SkapadAv = from.SkapadAv;

			to.Benamning = from.Namn;
			to.Fritext = from.Fritext;
		}
	}
}
